function [code_length] = entrop_alg_A(x, alph_size)
%with using Algorithm A
    x = round(x);
 	n=length(x);
    num = zeros(1, alph_size+1);
    cur_alph_size=0;
    code_length=0;
    
    min_ = min(min(x));
    for t = 1:n
            index = x(t) - min_ +1;
            p_A = probability_A(num(index), t-1, alph_size, cur_alph_size);
            code_length=code_length-log2(p_A);
             if (num(index) == 0)
                 cur_alph_size = cur_alph_size + 1;
             end;
             num(index) = num(index) + 1; 
    end;
    code_length=ceil(code_length)+1;
end


function [p] = probability_A(num, t, alph_size,cur_alph_size)
		if (cur_alph_size == alph_size)
        		p = num / t; 
        else
            if (num == 0)
                p = 1 /(t + 1)/(alph_size - cur_alph_size);
            else 
                p = num / (t + 1);
            end;
		end;
end
